<?php
namespace Home\Controller;
use Think\Controller;
class EventController extends Controller{
    public function receiveEvent($object,$public_id)
    {
        $contentStr = "";
        $arr=C("TMPL_PARSE_STRING");
        switch ($object->Event)
        {
            case "subscribe":
                $Subscribe = D('Subscribe');
                $list = $Subscribe -> where("public_id='$public_id'")->find();
                switch ($list['msgtype']){
                    case "text":
                        $contentStr=$list['content'];
                        $resultStr = transmitText($object, $list['content']);
                        break;
                    case "news":
                        $contentStr[] = array("Title" =>$list['title'],
                            "Description" =>$list['description'],
                            "PicUrl" =>$arr['__PUBLIC__'].$list['picurl'],
                            "Url" =>$list['url']);
                        $resultStr = transmitNews($object, $contentStr);
                        break;
                    case "image":
                        $media_id=$list['mediaid'];
                        //$resultStr = transmitText($object, $media_id);
                        $resultStr = transmitImage($object, $media_id);
                        break;
                    case "voice":
                        $media_id=$list['mediaid'];
                        $resultStr = transmitVoice($object, $media_id);
                        break;
                    case "video":
                        $media_id=$list['mediaid'];
                        $resultStr = transmitVideo($object, $list);
                        break;
                    case "music":
                        $resultStr = transmitMusic($object, $list);
                        break;
                }
                break;
            case "unsubscribe":
                break;
            case "CLICK":
                $val="".$_SERVER['SERVER_NAME']."/plug".$object->EventKey;
                $key_menu=$object->FromUserName.'menu';
                S($key_menu,$val);
                switch ($object->EventKey)
                {
                    case "video":
                        $media_id=$list['mediaid'];
                        $resultStr = transmitVideo($object, $list);
                        break;
                    case "text":
                        $contentStr=$list['content'];
                        $resultStr = transmitText($object, $list['content']);
                        break;
                    case "music":
                        $resultStr = transmitMusic($object, $list);
                        break;
                    default:
                        $contentStr[] = array("Title" =>$val,
                            "Description" =>"您正在使用的是方倍工作室的自定义菜单测试接口",
                            "PicUrl" =>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg",
                            "Url" =>"http://weiapptest.sinaapp.com/index.php/Home/MemberPublic/menu");
                        $resultStr = transmitNews($object, $contentStr);
                        break;
                }
                break;
            default:
                break;
    
        }
        return $resultStr;
    }
}